//
//  WSOrderSectionModel.m
//  FD
//
//  Created by xiaofang wang on 2019/1/9.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//   名字起不好了

#import "WSOrderSectionModel.h"
#import "WSOrderCellModel.h"

@implementation WSOrderSectionModel


//- (NSArray<WSOrderCellModel *> *)rowArr {
//
//    if (!self.ingredientClassifyList.count) { //空的
//        return @[]; //返回空数组
//    }
//
//    NSString *resultString = @""; //目标字符串
//    //一层一层剥壳
//    for (NSDictionary *firstLevelDic in self.ingredientClassifyList) {
//
//        //第一次拼接
//        resultString = [NSString stringWithFormat:@"%@: ",firstLevelDic[@"name"]];
////        FDLog(@"111:%@",resultString);
//
//        NSArray *ingredientList = firstLevelDic[@"ingredientList"];
//
//        if (!ingredientList.count) { //空
//            continue; //结束本次循环 继续i下一次
//        }
//
//
//
//        //第二层目标字符串:
//        NSString *secondLevelString = @"";
//
//        NSMutableArray *smaltitleArrM = @[].mutableCopy;
//        for (NSDictionary *secondLevelDic in ingredientList) {
//            NSString *smalName = secondLevelDic[@"name"];
//            [smaltitleArrM addObject:smalName]; //取出小name放入数组中
//        }
//
//        secondLevelString = [smaltitleArrM componentsJoinedByString:@"、"]; //将数组中的字符串以 、进行分割
//        FDLog(@"222:%@",secondLevelString);
//
//        resultString = [resultString stringByAppendingFormat:@"%@\n",secondLevelString];
//    }
//
//
//    //如果 resultString 非空就保存到数组中
//    if ([NSString isEmptyString:resultString]) {
//
//        return @[];
//    }
//
//    WSOrderCellModel *cellModel = [[WSOrderCellModel alloc] init];
//    cellModel.name = resultString;
//
//    //装入数组中返回。
//    return @[cellModel];
//}


- (NSArray<WSOrderCellModel *> *)rowArr {
    
    if (!self.ingredientClassifyList.count) { //空的
        return @[]; //返回空数组
    }
    
    NSString *resultString = @""; //目标字符串
    
    //2019-2-12目标字符串数组
    NSMutableArray *resultStrArrM = [[NSMutableArray alloc] initWithCapacity:0];
    
    //一层一层剥壳
    for (NSDictionary *firstLevelDic in self.ingredientClassifyList) {
    
        //第一次拼接
        NSString *firstLevelString = [NSString stringWithFormat:@"%@: ",firstLevelDic[@"name"]];
        //        FDLog(@"111:%@",resultString);
        
        NSArray *ingredientList = firstLevelDic[@"ingredientList"];
        
        if (!ingredientList.count) { //空
            continue; //结束本次循环 继续i下一次
        }
        
        
        
        //第二层目标字符串:
        NSString *secondLevelString = @"";
        
        NSMutableArray *smaltitleArrM = @[].mutableCopy;
        for (NSDictionary *secondLevelDic in ingredientList) {
            NSString *smalName = secondLevelDic[@"name"];
            [smaltitleArrM addObject:smalName]; //取出小name放入数组中
        }
        
        secondLevelString = [smaltitleArrM componentsJoinedByString:@"、"]; //将数组中的字符串以 、进行分割
        
        firstLevelString = [NSString stringWithFormat:@"%@%@",firstLevelString,secondLevelString];
        
//        FDLog(@"222:%@",firstLevelString);
        //装入数组中
        [resultStrArrM addObject:firstLevelString];
    }
    
    
    //2019-2-12 拼接换行符号
    resultString = [resultStrArrM componentsJoinedByString:@"\n"];
    resultString = [NSString stringWithFormat:@"%@\n",resultString]; //最后一个也添加换行符号
    
    //如果 resultString 非空就保存到数组中
    if ([NSString isEmptyString:resultString]) {
        
        return @[];
    }
    
    WSOrderCellModel *cellModel = [[WSOrderCellModel alloc] init];
    cellModel.name = resultString;
    
    //装入数组中返回。
    return @[cellModel];
}




/**2019-2-21 配料价格累加和*/
- (CGFloat)ingredientSumPrice {
    
    //求配料累加和
    CGFloat sumPeiLiaoPrice = 0.0;
    
    for (NSDictionary *firstLevelDic in self.ingredientClassifyList) {
        NSArray *firstArr = firstLevelDic[@"ingredientList"];
        for (NSDictionary *secondLevelDic in firstArr) {
            CGFloat price = [secondLevelDic[@"price"] floatValue];
            
            sumPeiLiaoPrice += price;
        }
    }
    
//    FDLog(@"配料累加和:%f",sumPeiLiaoPrice);
    
    return sumPeiLiaoPrice;
}

    
@end
